package com.kpijavatraining6.module2.mainMenu;

import com.kpijavatraining6.module2.ScannerOfInput;
import com.kpijavatraining6.module2.sessionTools.AdminSession;
import com.kpijavatraining6.module2.sessionTools.AuthorisationMenu;
import com.kpijavatraining6.module2.sessionTools.Session;
import com.kpijavatraining6.module2.sessionTools.UserSession;

import java.net.Authenticator;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Vladislav
 * Date: 07.11.13
 * Time: 16:30
 * To change this template use File | Settings | File Templates.
 */
public class Menu {
    private Session session;
    public void runMenu(){
        AuthorisationMenu authorisationMenu = new AuthorisationMenu();
        authorisationMenu.analyzeKeys();
        int mode;
        if(authorisationMenu.isAdmin()) {
            session = new AdminSession();
        } else {
            session = new UserSession(authorisationMenu.getName());
        }
        while(true) {
            System.out.println("e - exit, n - new user, s - show statistic, start - start game");
            ScannerOfInput scanner = new ScannerOfInput();
            String action = scanner.inputScanner();
            newAction(action);
        }
    }
    public void newAction(String action) {
        if (action.equals(session.EXIT)) {
            session.exit();
        }
        if(action.equals(session.NEW_USER)) {
            session.newUser();
        }
        if(action.equals(session.SHOW_STATISTIC)) {
            session.showStatistic();
        }
        if( (action.equals(session.START)) ) {
            session.startGame();
        }

    }
}
